﻿using System.Collections.Generic;
using System.Linq;
using Turquoise.Caching.Microsoft;
using Turquoise.Providers.Entities;
using Turquoise.Providers.EntityFramework;

namespace Turquoise.Providers
{
    public class LanguageProvider
    {
        public List<string> GetAllCodeList()
        {
            const string key = "Turquoise.Providers.LanguageProvider.GetAllCodeList";
            var memoryCacheManager = new MemoryCacheManager();
            if (memoryCacheManager.Get(key) != null) return (List<string>) memoryCacheManager.Get(key);
            var databaseProvider = new Repository<Language>(new DatabaseContext());
            var languageCodeList = databaseProvider.DbSet().Where(e=>e.IsApproved).Select(s=>s.LanguageCode).ToList();
            memoryCacheManager.Add(key,languageCodeList);
            return languageCodeList;
        }
    }
}
